/*
 * @Date: 2024-07-25 10:29:58
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2024-11-05 16:33:58
 * @Description: 登录
 */
import { defAxios as request } from '@/utils/http'
import { TokenUtils } from '@/utils/auth'
import { ElMessage } from 'element-plus';



export function useLoginApi () {
  return {
    login: () => {
      return new Promise(resolve => {
        request({
          url: '/login',
          data: {
            userCode: '34admin',
            password: 'dsyf905',
          },
          method: 'post',
          headers: { isToken: false },
        }).then(res => {
          console.log('useLoginApi login', res)
          if(res.code === 200) {
            TokenUtils.setAuthorization(res.data.Authorization)
            ElMessage.success('登录成功！')
          } else {
            ElMessage.error('登录失败！')
            TokenUtils.setAuthorization('')
          }
        });
      })
    }
  }
}
